package chapter3.lc26;

//LC 26 . 删除有序数组中的重复项

/**
 * 双指针，如果nums[i] == nums[j-1]就跳过
 */
public class RemoveDuplicatesSorted {
    public int removeDuplicates(int[] nums) {
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            if (j < 1) {
                nums[j++] = nums[i];
            }else if (nums[j-1] != nums[i]) {
                nums[j++] = nums[i];
            }
        }
        return j;
    }
}
